package com.atguigu.gulimail.member.controller.TestController;

import com.atguigu.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("loaderBalancer")
public class TestLoaderBalancerController {
    @Autowired
    DiscoveryClient discoveryClient;

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/test1")
    public R testLoaderBalancer() {
/*        List<ServiceInstance> instances = discoveryClient.getInstances("gulimail-coupon");
        String url = String.format("http://%s:%s",instances.get(0).getHost(),instances.get(0).getPort())+"/coupon/couponspu/from/member";
        R forObject = restTemplate.getForObject(url, R.class);*/
        R forObject = restTemplate.getForObject("http://gulimail-coupon/coupon/couponspu/from/member", R.class);
        return forObject;
    }
}
